﻿using System.Linq;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic.media;

namespace uREST.CMS.Extensions
{
    public static class UserExtensions
    {
        public static bool CanAccess(this User user, Document doc)
        {
            return user.Applications.Any(app => app.alias.ToLower() == "content") && (user.StartNodeId <= 0 || ("," + doc.Path + ",").Contains("," + user.StartNodeId + ","));
        }

        public static bool CanAccess(this User user, Media media)
        {
            return user.Applications.Any(app => app.alias.ToLower() == "media") && (user.StartMediaId <= 0 || ("," + media.Path + ",").Contains("," + user.StartMediaId + ","));
        }
    }
}
